package jfrederick8;

/**
 * This class represents a square tile on the field of play which can be 
 * seen by the player. A Tile may hold objects such as Items, Containers or
 * Story Characters.
 * 
 * @author John Frederick
 * @version 1.0 - 2 February 2012
 */
public class Tile {
	/** represents the horizontal location of this tile */
	private int x;
	/**Field this value represents the vertical location of this tile */
	private int y;
	/** represents the intensity of the grid lines around the tiles */
	private static int edgeBrightness;
	/** represents the width of each tile */
	private final int WIDTH = 25;
	/** represents the height of each tile */
	private final int HEIGHT = 25;
	/** tells whether a StoryCharacter is able to walk onto this tile */
	private boolean walk;
	/** tells whether a StoryCharacter is able to fly over this tile */
	private boolean fly;
	/** tells whether each player is able to see the contents of this tile */
	private boolean[] see;
	/** tells the passability of the tile */
	private int type;
	/** the number of moves required to walk onto this tile */
	private int walkWeight;
	/** the number of moves required to fly onto this tile */
	private int flyWeight;
	/** this tracks the movement weights required to enter a space during the dijkstra's algorithm */
	private int alterableWeight;
	/** the name of the terrain type to be displayed in the basic description menu */
	private String displayName;
	/** the defensive bonus applied to the GameCharacter standing on this tile */
	private int defBonus;
	
	/**
	 * This constructor instantiates the tile in a certain location within the field of play. It also calls the setTileType method in order to specify further characteristics of the Tile.
	 * 
	 *  @param x This represents the horizontal location of this Tile on the field of play.
	 *  @param y This represents the vertical location of this Tile on the field of play.
	 *  @param type This represents the characteristics of the Tile which effect game play, such as whether a certain player can see thie Tile or whether a Story Character may walk on this Tile. See setTileType for specifications of which Integer refers to which characteristics.
	 */
	public Tile(int x, int y, int type){
		this.x = x;
		this.y = y;
		this.type = type;
		setTileType(type);
		edgeBrightness = 100;
		//TODO:possibly other variables to set
	}//end constructor Tile
	
	/**
	 * This method applies certain characteristics to each tile when it is created. (Such as whether a StoryCharacter can walk on this tile)
	 * 
	 * @param type represents the characteristics of the tile to be attributed
	 * 		  0: tile can be both walked on and flown over
	 * 		  1: tile can be flown over but not walked on
	 * 		  2: tile can be neither flown over nor walked on
	 */
	private void setTileType(int type){
		switch (type){
		case 0: walk = true;
			fly = true;
			walkWeight = 1;
			flyWeight = 1;
			displayName = "Plain";
			defBonus = 0;
			break;
		case 1: walk = false;
			fly = true;
			walkWeight = 100;
			flyWeight = 1;
			displayName = "River";
			defBonus = 1;
			break;
		case 2: walk = false;
			fly = false;
			walkWeight = 100;
			flyWeight = 100;
			displayName = "Fort";
			defBonus = 0;
			break;
		case 3: walk = true;
			fly = false;
			walkWeight = 2;
			flyWeight = 1;
			displayName = "Forest";
			defBonus = 2;
			break;
		case 4: walk = true;
			fly = true;
			walkWeight = 3;
			flyWeight = 1;
			displayName = "Mountain";
			defBonus = 1;
			break;
		}
		alterableWeight = 100;
	}//end method setTypeType
	
	//TODO: set all seeables when creating tile
	/**
	 * This method regulates whether a specified player is able to see the contents of each tile. (Fog of War)
	 * 
	 * @param player this represents each player participating in the game
	 * @param seen this allows or denies access to seeing each tile to the specified player
	 */
	public void setSeeable(int player, boolean seen){
		see[player] = seen;
	}//end method setSeeable
	
	/**
	 * This allows outside access to the location of this tile
	 * 
	 * @return the horizontal location of this tile on the field of play
	 */
	public int getX(){
		return this.x;
	}//end getter getX
	
	/**
	 * This allows outside access to the location of this tile
	 * 
	 * @return the vertical location of this tile on the field of play
	 */
	public int getY(){
		return this.y;
	}//end getter getY
	
	/**
	 * Allows access to the size of each individual tile
	 * 
	 * @return the horizontal size of each tile
	 */
	public int getWidth(){
		return WIDTH;
	}//end getter getWidth
	
	/**
	 * Allows access to the size of each individual tile
	 * 
	 * @return the vertical size of each tile
	 */
	public int getHeight(){
		return HEIGHT;
	}//end getter getHeight
	
	/**
	 * This checks whether characters may walk on this individual tile
	 * 
	 * @return true if a StoryCharacter may walk on this tile
	 */
	public boolean isWalkable(){
		return walk;
	}//end method isWalkable
	
	/**
	 * This checks whether characters may fly over this individual tile
	 * 
	 * @return true if a StoryCharacter may fly over this tile
	 */
	public boolean isFlyable(){
		return fly;
	}//end method isFlyable
	
	/**
	 * This checks whether a player may see this individual tile
	 * 
	 * @return true if the player can see this tile
	 */
	public boolean isSeeable(int player){
		return see[player];
	}//end method isSeeable
	
	/**
	 * Used to set the intensity of tile outlines
	 * 
	 * @param brightness the intensity of the grid lines to be drawn around each tile
	 */
	public void setEdgeBrightness(int brightness){
		Tile.edgeBrightness = brightness;
	}//end setter edgeBrightness
	
	/**
	 * used to get the intensity of the tile's grid lines
	 * 
	 * @return the intensity of the grid lines to be drawn
	 */
	public int getEdgeBrightness(){
		return edgeBrightness;
	}//end getter edgeBrightness
	
	/**
	 * allows access to the tile's type
	 * 
	 * @return the type representing the characteristics of the tile
	 */
	public int getType(){
		return type;
	}
	
	/**
	 * This allows access to the movement requirement for walking into this tile
	 * 
	 * @return the number of moves required to walk into this tile
	 */
	public int getWalkWeight(){
		return walkWeight;
	}//end getter getWalkWeight
	
	/**
	 * This allows access to the movement requirement for walking into this tile
	 * 
	 * @return the number of moves required to walk into this tile
	 */
	public int getFlyWeight(){
		return flyWeight;
	}//end getter getFlyWeight
	
	/**
	 * allows access to a ever-changing alterable weight in order to run dijkstra's algorithm
	 * 
	 * @return the weights used to get from the origin to this tile
	 */
	public int getAlterableWeight(){
		return alterableWeight;
	}//end getter getAlterableWeight
	
	/**
	 * allows changes to the alterable weight variable in order to track movement during dijkstra's algorithm
	 * 
	 * @param alterable the new value of alterableWeight
	 */
	public void setAlterableWeight(int alterable){
		this.alterableWeight = alterable;
	}//end setter setAlterableWeight
	
	/**
	 * Allows access to the string title of the tile's type
	 * 
	 * @return the name to display for each tile
	 */
	public String getDisplayName(){
		return displayName;
	}//end getter getDisplayName
	
	/**
	 * Allows access to the defense modifier caused by each tile
	 * 
	 * @return defensive bonus from standing on this tile
	 */
	public int getDefBonus(){
		return defBonus;
	}//end getter getDefBonus
}//end class Tile
